﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.Rules;

namespace YaAppoint.Web.Controllers
{
    public class RuleTemplateController(IRuleTemplateAppService ruleTemplateAppService) : AbpController
    {
        private readonly IRuleTemplateAppService _ruleTemplateAppService = ruleTemplateAppService;

        /// <summary>
        /// 加载树形数据
        /// </summary>
        [HttpGet("/api/rule-template/load-tree-data")]
        public async Task<IActionResult> GetTreeData(string? filterName)
        {
            return new JsonResult(await _ruleTemplateAppService.GetTreeDate(filterName));
        }

        /// <summary>
        /// 新建文目录
        /// </summary>
        [HttpPost("/api/rule-template/create-directory")]
        public async Task<IActionResult> CreateDirectory([FromBody] RuleTemplateCreateDto dto)
        {
            return new JsonResult(await _ruleTemplateAppService.CreateDirectory(dto));
        }

        /// <summary>
        /// 目录修改提交
        /// </summary>
        [HttpPost("/api/rule-template/edit-dir-submit")]
        public async Task<IActionResult> EditDirectory([FromBody] RuleTemplateDto dto)
        {
            return new JsonResult(await _ruleTemplateAppService.EditDirectory(dto));
        }

        /// <summary>
        /// 删除目录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("/api/rule-template/delete-directory")]
        public async Task<IActionResult> DeleteDirectory(Guid id)
        {
            return new JsonResult(await _ruleTemplateAppService.DeleteDirectory(id));
        }

        /// <summary>
        /// 新建模板
        /// </summary>
        [HttpPost("/api/rule-template/create-template")]
        public async Task<IActionResult> CreateTemplate([FromBody]RuleTemplateCreateDto dto)
        {
            return new JsonResult(await _ruleTemplateAppService.CreateTemplate(dto));
        }

        /// <summary>
        /// 模板编辑提交
        /// </summary>
        [HttpPost("/api/rule-template/template-edit-submit")]
        public async Task<IActionResult> TemplateEditSubmit([FromBody]RuleTemplateDto dto)
        {
            return new JsonResult(await _ruleTemplateAppService.EditTemplate(dto));
        }

        /// <summary>
        /// 删除模板
        /// </summary>
        [HttpGet("/api/rule-template/template-delete")]
        public async Task<IActionResult> DeleteTemplate(Guid id)
        {
            return new JsonResult(await _ruleTemplateAppService.DeleteTemplate(id));
        }

        /// <summary>
        /// 加载详情
        /// </summary>
        [HttpGet("/api/rule-template/get-detail")]
        public async Task<IActionResult> GetDetail(Guid id)
        {
            return new JsonResult(await _ruleTemplateAppService.LoadDetail(id));
        }

    }
}
